	.GLOBAL	AD_BUF0
	.GLOBAL	AD_BUF1
	.GLOBAL AD_BUF2
	.GLOBAL	AD_BUF3
	.GLOBAL	AD_BUF4
	.GLOBAL	AD_BUF5
	.SECTION	.XBSS,	BSS,	XMEMORY
AD_BUF0:	.SPACE	2
AD_BUF1:	.SPACE	2
AD_BUF2:	.SPACE	2
AD_BUF3:	.SPACE	2
AD_BUF4:	.SPACE	2
AD_BUF5:	.SPACE	2

.INCLUDE	"p33FJ16GS502.INC"
.INCLUDE	"MACRO.INC"
.GLOBAL	__ADCP0Interrupt
.GLOBAL	__ADCP1Interrupt
.GLOBAL	__ADCP2Interrupt

.TEXT

__ADCP0Interrupt:				; AD PAIR 0(AN0,AN1) 
	NOP
	PUSH.S
	
	BCLR IFS6, #ADCP0IF			; CLEAR PAIR0 INTERRUTP FLAG
	MOVFF	ADCBUF0, AD_BUF0	; I
	MOVFF	ADCBUF1, AD_BUF1	; V
	CALL	FILTER0
	CALL	FILTER1
	CALL	PID_CALCULATE
	MOVFF	PID_OUT, MDC
	;MOVFF #0XFFFF, PORTA
	POP.S
	NOP
	RETFIE

__ADCP1Interrupt:				; AD PAIR 1(AN2,AN3)
	NOP
	PUSH.S
	
	BCLR IFS6, #ADCP1IF			; CLEAR PAIR1 INTERRUPT FLAG
	;--------------------------------
	
	MOVFF	ADCBUF2, AD_BUF2	; I
	MOVFF	ADCBUF3, AD_BUF3	; V

	CALL 	FILTER2
	CALL	FILTER3
	CALL 	PID_CALCULATE
	MOVFF	PID_OUT, MDC		; PUT PID_OUT RESULT INTO MASTER DUTY CYCLE REGISTER(MDC)

	;--------------------------------	
	
	POP.S
	NOP
	RETFIE

__ADCP2Interrupt:				; AD PAIR 2(AN4,AN5) 
	NOP
	PUSH.S
	
	BCLR IFS7, #ADCP2IF			; CLEAR PAIR2 INTERRUPT FLAG
	MOVFF	ADCBUF4, AD_BUF4	; I
	MOVFF	ADCBUF5, AD_BUF5	; V

	CALL 	FILTER4
	CALL	FILTER5
	CALL 	PID_CALCULATE_I
	MOVFF	PID_OUT, MDC		; PUT PID_OUT RESULT INTO MASTER DUTY CYCLE REGISTER(MDC)
		
	POP.S
	NOP
	RETFIE

	.END